﻿using Abp.Domain.Entities;
using GN.Pay.Core.Values.Channel;
using GN.Pay.TradeChannel;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GN.Pay.Utils;

namespace GN.Pay.Core.Entities
{
    /// <summary>
    /// 队列错误消息
    /// </summary>
    [Table("Queue_ErrorMessage")]
    [Serializable]
    public class QueueErrorMessage : Entity<long>
    {
        /// <summary>
        /// 消息
        /// </summary>
        public int MessageType { get; set; }

        /// <summary>
        /// 消息Key
        /// </summary>
        public string MessageKey { get; set; }

        /// <summary>
        /// 消息类型
        /// </summary>
        [Required]
        public string MessageContent { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime Created { get; set; }

        /// <summary>
        /// 创建结果
        /// </summary>
        /// <returns></returns>
        public T CreateResult<T>() where T : class, new()
        {
            if (string.IsNullOrWhiteSpace(MessageContent))
            {
                return null;
            }
            return MessageContent.JsonToObject<T>(true);            
        }

    }
}
